package org.ushio.nchu_22201406.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.ushio.common_module.entity.MyPackage;
import org.ushio.nchu_22201406.pojo.PackageRecord;
import org.ushio.nchu_22201406.service.packageService;
import org.ushio.nchu_22201406.dao.packageDao;
import org.ushio.nchu_22201406.dao.packageRecordDao;

import java.sql.Date;
import java.util.List;

@Service
public class packageServiceImpl implements packageService {
    @Autowired
    private packageDao packageDao;
    @Autowired
    private packageRecordDao packageRecordDao;

    @Override
    public void updatePackageId(String phoneNumber, int newPackageId) {
        packageDao.updatePackageIdByPhoneNumber(phoneNumber, newPackageId);
        // 记录套餐变更
        org.ushio.nchu_22201406.pojo.PackageRecord packageRecord = new PackageRecord();
        packageRecord.setPhoneNumber(phoneNumber);
        packageRecord.setPackageId(newPackageId);
        packageRecord.setPurchaseDate(new java.sql.Date(System.currentTimeMillis()));  // 使用当前时间

        // 插入新的套餐记录
        packageRecordDao.insertPackageRecord(packageRecord.getPhoneNumber(),
                packageRecord.getPackageId(),
                (Date) packageRecord.getPurchaseDate());
    }
    @Override
    public List<MyPackage> getAllPackages() {
        return packageDao.getAllPackages();
    }
    @Override
    public void updatePackage(MyPackage myPackage) {
        packageDao.updatePackage(myPackage);
    }
}
